#include <iostream>
#include <pthread.h>

using namespace std;

class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex_p) :mutex_p_(mutex_p)
    {}
    void lock()
    {
        pthread_mutex_lock(mutex_p_);
    }
    void unlock()
    {
        pthread_mutex_unlock(mutex_p_);
    }

public:
    pthread_mutex_t* mutex_p_;
};


class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex_p) :mutex_(mutex_p)
    {
        mutex_.lock();    //构造函数进行加锁
    }
    ~LockGuard()
    {
        mutex_.unlock(); //析构函数进行解锁
    }
public:
    Mutex mutex_;
};